package io.github.xbeeant.eoffice.service.impl;

import io.github.xbeeant.core.IdWorker;
import io.github.xbeeant.eoffice.config.AbstractSecurityMybatisPageHelperServiceImpl;
import io.github.xbeeant.eoffice.mapper.ResourcesPermMapper;
import io.github.xbeeant.eoffice.model.ResourcesPerm;
import io.github.xbeeant.eoffice.service.IResourcesPermService;
import io.github.xbeeant.spring.mybatis.pagehelper.IMybatisPageHelperDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 资源权限矩阵
 */
@Service
public class ResourcesPermServiceImpl extends AbstractSecurityMybatisPageHelperServiceImpl<ResourcesPerm, Long> implements IResourcesPermService {

    @Autowired
    private ResourcesPermMapper resourcesPermMapper;

    @Override
    public IMybatisPageHelperDao<ResourcesPerm, Long> getRepositoryDao() {
        return this.resourcesPermMapper;
    }

    @Override
    public void setDefaults(ResourcesPerm record) {
        if (record.getPid() == null) {
            record.setPid(IdWorker.getId());
        }
    }

    @Override
    public void newResource(Long rid, Long userId) {
        // 写入权限
        ResourcesPerm perm = new ResourcesPerm();
        perm.setComment(true);
        perm.setCopy(true);
        perm.setDownload(true);
        perm.setEdit(true);
        perm.setFillForms(true);
        perm.setModifyContentControl(true);
        perm.setModifyFilter(true);
        perm.setPrint(true);
        perm.setReview(true);
        perm.setRid(rid);
        perm.setTargetId(userId);
        insertSelective(perm);
    }
}
